package serverapp;

import java.io.*;

public class SerializedFiles
{
	/*public static void main(String[]args)
	{
		loadDVDTable();
		loadCustomerTable();
	}*/
	
	public static void loadDVDTable()
	{
		try
		{
			// Read Serializable DVD File
			FileInputStream fis = new FileInputStream("Movies.ser");
			ObjectInputStream ois = new ObjectInputStream(fis);// Open File
			DVD myDVD = new DVD();			
			
			boolean recordExists = true;
			do
			{
				try
				{
					myDVD = (DVD)ois.readObject();
					//System.out.println(myDVD);
					Database.insertDVD(myDVD.getTitle(), myDVD.getCategory(), myDVD.isNewRelease(), myDVD.isAvailable());
				}
				catch(EOFException eof)
				{
					recordExists = false;
				}
			}while(recordExists);
			//if (ois!=null)
			ois.close();
		}
		catch (IOException io) // Manditory
		{
			System.out.println("IO error");
		}
		catch (ClassNotFoundException cnf) // Manditory
		{
			System.out.println("Class not found error");
		}
	}
	
	public static void loadCustomerTable()
	{
		try
		{
			// Read Serializable File
			FileInputStream fis = new FileInputStream("Customers.ser");
			ObjectInputStream ois = new ObjectInputStream(fis);// Open File
			Customer myCustomer = new Customer();			
			
			boolean recordExists = true;
			do
			{
				try
				{
					myCustomer = (Customer)ois.readObject();
					//System.out.println(myCustomer.getSurname());
					Database.insertCustomer(myCustomer.getPhoneNum(), myCustomer.getSurname(), myCustomer.getName(), myCustomer.getCredit());
				}
				catch(EOFException eof)
				{
					recordExists = false;
				}
			}while(recordExists);
			//if (ois!=null)
			ois.close();
		}
		catch (IOException io) // Manditory
		{
			System.out.println("IO error");
		}
		catch (ClassNotFoundException cnf) // Manditory
		{
			System.out.println("Class not found error");
		}
	}
}